package com.hgd.security.evp.swagger.controller;

import cn.hgd11.swagger.extension.annotation.Hgd11SwaggerModel;
import cn.hgd11.swagger.extension.annotation.Hgd11SwaggerParameter;
import cn.hgd11.swagger.extension.annotation.Hgd11SwaggerProperties;
import cn.hgd11.swagger.extension.annotation.Hgd11SwaggerProperty;
import com.alibaba.fastjson.JSONObject;
import com.hgd.security.evp.swagger.entity.TestEntity;
import com.hgd.security.evp.swagger.util.SpringContextUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerExecutionChain;
import springfox.documentation.spring.web.DocumentationCache;
import springfox.documentation.spring.web.PropertySourcedRequestMappingHandlerMapping;
import springfox.documentation.swagger2.web.Swagger2Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ：尚村山夫
 * @date ：Created in 2019/8/13 23:36
 * @modified By：
 */
@RestController
//@Api(tags = "测试2Controller")
@RequestMapping("test2")
public class Test2Controller {

    @Hgd11SwaggerModel(
        description = "用户信息",title = "paramP",type = "body",
        properties = @Hgd11SwaggerProperties(value = {
            @Hgd11SwaggerProperty(description = "用户名",name = "userName",index="userName",required = true,example = "wangkaige"),
            @Hgd11SwaggerProperty(description = "用户部门",name = "userDept",index = "userDept",children = {"deptName","deptCode","deptType"}),

            @Hgd11SwaggerProperty(description = "部门名称",name = "deptName",index="deptName"),
            @Hgd11SwaggerProperty(description = "部门编号",name = "deptCode",index="deptCode"),
            @Hgd11SwaggerProperty(description = "部门类型",name = "deptType",index="deptType",children = {"deptTypeName"}),

            @Hgd11SwaggerProperty(description = "部门类型名称",name = "deptTypeName",index="deptTypeName")
        })
    )
    @GetMapping("/test01")
    @ApiOperation("测试01")
    public JSONObject test01(HttpServletRequest request,
        @Hgd11SwaggerParameter(
            description = "入参",
            in = "body",
            name = "paramjobj",
            model = @Hgd11SwaggerModel(
                description = "用户信息",title = "paramP",type = "body",
                properties = @Hgd11SwaggerProperties(value = {
                    @Hgd11SwaggerProperty(description = "用户名",name = "userName",index="userName",required = true,example = "wangkaige"),
                    @Hgd11SwaggerProperty(description = "用户部门",name = "userDept",index = "userDept",children = {"deptName","deptCode","deptType"}),

                    @Hgd11SwaggerProperty(description = "部门名称",name = "deptName",index="deptName"),
                    @Hgd11SwaggerProperty(description = "部门编号",name = "deptCode",index="deptCode"),
                    @Hgd11SwaggerProperty(description = "部门类型",name = "deptType",index="deptType",children = {"deptTypeName"}),

                    @Hgd11SwaggerProperty(description = "部门类型名称",name = "deptTypeName",index="deptTypeName")
                })
            )
        )
        JSONObject paramjobj,JSONObject second) {
        TestEntity jsonObject = new TestEntity();
        jsonObject.setName("wangkaige");
        jsonObject.setId(1);

        try {
            BeanFactory beanByClassType = SpringContextUtil.getBeanByClassType(BeanFactory.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            DefaultListableBeanFactory beanByClassType1 =
                SpringContextUtil.getBeanByClassType(DefaultListableBeanFactory.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Swagger2Controller beanByClassType = SpringContextUtil.getBeanByClassType(Swagger2Controller.class);
            PropertySourcedRequestMappingHandlerMapping beanByClassType1 =
                SpringContextUtil.getBeanByClassType(PropertySourcedRequestMappingHandlerMapping.class);
            HandlerExecutionChain handler = beanByClassType1.getHandler(request);

            TestController beanByClassType2 = SpringContextUtil.getBeanByClassType(TestController.class);
            beanByClassType2 = new TestController();
            TestController beanByClassType3 = SpringContextUtil.getBeanByClassType(TestController.class);

            DocumentationCache beanByClassType4 = SpringContextUtil.getBeanByClassType(DocumentationCache.class);
            String s = JSONObject.toJSONString(beanByClassType4);
            System.out.println();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new JSONObject();
    }
}
